﻿namespace Restaurant
{
    using System;
    using System.IO;
    using System.Text;

    public class FileReader
    {
        /// <summary>
        /// Database reader
        /// </summary>
        /// <param name="articlesFileName"></param>
        /// <param name="errorFileName"></param>
        /// <returns></returns>
        public static StringBuilder ReadFile(string articlesFileName, string errorFileName)
        {
            StringBuilder articles = new StringBuilder();
            try
            {
                using (StreamReader reader = File.OpenText(articlesFileName))
                {
                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        articles.AppendLine(line);
                        line = reader.ReadLine();
                    }
                }

            }
            catch (System.Exception)
            {
                using (StreamWriter writer = new StreamWriter(errorFileName, true))
                {
                    writer.WriteLine(string.Format("[{0}]: Couldnt find articles database file (articles.txt)!", DateTime.Now));
                }
            }

            return articles.Replace("\t", string.Empty);
        }
    }
}
